#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
int main()
{
    int t = 0, n = 0, i = 0, j = 0, k = 0, f = 0;
    int a[50][50] = { 0 };
    scanf("%d", &t);
    for (k = 0; k < t; k++)
    {
        f = 0;
        scanf("%d", &n);
        for (i = 0; i < n; i++)
        {
            for (j = 0; j < n; j++)
            {
                scanf("%d", &a[i][j]);
            }
        }
        for (i = 0; i < n; i++)
        {
            for (j = 0; j < i; j++)
            {
                if (a[i][j] != 0)
                {
                    printf("NO\n");
                    f = 1;
                    break;
                }
            }
        }
    }
    if (f == 0)
    {
        printf("YES\n");
    }
    return 0;
}